// Verilated -*- C++ -*-
// DESCRIPTION: Verilator output: Design implementation internals
// See Vtop.h for the primary calling header

#include "verilated.h"
#include "verilated_dpi.h"

#include "Vtop___024root.h"

VL_ATTR_COLD void Vtop___024root___eval_static(Vtop___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    Vtop__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    Vtop___024root___eval_static\n"); );
}

VL_ATTR_COLD void Vtop___024root___eval_initial(Vtop___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    Vtop__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    Vtop___024root___eval_initial\n"); );
    // Body
    vlSelf->__Vtrigrprev__TOP__clk = vlSelf->clk;
    vlSelf->__Vtrigrprev__TOP__rst_n = vlSelf->rst_n;
}

VL_ATTR_COLD void Vtop___024root___eval_final(Vtop___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    Vtop__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    Vtop___024root___eval_final\n"); );
}

VL_ATTR_COLD void Vtop___024root___eval_triggers__stl(Vtop___024root* vlSelf);
#ifdef VL_DEBUG
VL_ATTR_COLD void Vtop___024root___dump_triggers__stl(Vtop___024root* vlSelf);
#endif  // VL_DEBUG
VL_ATTR_COLD void Vtop___024root___eval_stl(Vtop___024root* vlSelf);

VL_ATTR_COLD void Vtop___024root___eval_settle(Vtop___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    Vtop__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    Vtop___024root___eval_settle\n"); );
    // Init
    CData/*0:0*/ __VstlContinue;
    // Body
    vlSelf->__VstlIterCount = 0U;
    __VstlContinue = 1U;
    while (__VstlContinue) {
        __VstlContinue = 0U;
        Vtop___024root___eval_triggers__stl(vlSelf);
        if (vlSelf->__VstlTriggered.any()) {
            __VstlContinue = 1U;
            if (VL_UNLIKELY((0x64U < vlSelf->__VstlIterCount))) {
#ifdef VL_DEBUG
                Vtop___024root___dump_triggers__stl(vlSelf);
#endif
                VL_FATAL_MT("vsrc/top.v", 77, "", "Settle region did not converge.");
            }
            vlSelf->__VstlIterCount = ((IData)(1U) 
                                       + vlSelf->__VstlIterCount);
            Vtop___024root___eval_stl(vlSelf);
        }
    }
}

#ifdef VL_DEBUG
VL_ATTR_COLD void Vtop___024root___dump_triggers__stl(Vtop___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    Vtop__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    Vtop___024root___dump_triggers__stl\n"); );
    // Body
    if ((1U & (~ (IData)(vlSelf->__VstlTriggered.any())))) {
        VL_DBG_MSGF("         No triggers active\n");
    }
    if (vlSelf->__VstlTriggered.at(0U)) {
        VL_DBG_MSGF("         'stl' region trigger index 0 is active: Internal 'stl' trigger - first iteration\n");
    }
}
#endif  // VL_DEBUG

void Vtop___024root____Vdpiimwrap_top__DOT__u_data_mem__DOT__cpu_pmem_read_TOP(IData/*31:0*/ raddr, IData/*31:0*/ &cpu_pmem_read__Vfuncrtn);
void Vtop___024root____Vdpiimwrap_top__DOT__ebreak_TOP();
extern const VlUnpacked<CData/*0:0*/, 1024> Vtop__ConstPool__TABLE_hd2f4e6a9_0;
extern const VlUnpacked<CData/*2:0*/, 1024> Vtop__ConstPool__TABLE_h2a6e909c_0;
extern const VlUnpacked<CData/*1:0*/, 1024> Vtop__ConstPool__TABLE_h35963e2c_0;
extern const VlUnpacked<CData/*1:0*/, 1024> Vtop__ConstPool__TABLE_h6a562c3a_0;
extern const VlUnpacked<CData/*0:0*/, 1024> Vtop__ConstPool__TABLE_h22430f06_0;
extern const VlUnpacked<CData/*0:0*/, 1024> Vtop__ConstPool__TABLE_hd9fef700_0;
extern const VlUnpacked<CData/*3:0*/, 1024> Vtop__ConstPool__TABLE_h3b383ffb_0;
extern const VlUnpacked<CData/*1:0*/, 1024> Vtop__ConstPool__TABLE_h36305c5d_0;
extern const VlUnpacked<CData/*0:0*/, 1024> Vtop__ConstPool__TABLE_h1e65f990_0;
extern const VlUnpacked<CData/*1:0*/, 1024> Vtop__ConstPool__TABLE_hd3c38cd5_0;
extern const VlUnpacked<CData/*0:0*/, 1024> Vtop__ConstPool__TABLE_hca46ea29_0;
extern const VlUnpacked<CData/*2:0*/, 128> Vtop__ConstPool__TABLE_hdfd0dbe7_0;
void Vtop___024root____Vdpiimwrap_top__DOT__u_data_mem__DOT__cpu_pmem_write_TOP(IData/*31:0*/ waddr, IData/*31:0*/ wdata, CData/*7:0*/ wmask);

VL_ATTR_COLD void Vtop___024root___stl_sequent__TOP__0(Vtop___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    Vtop__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    Vtop___024root___stl_sequent__TOP__0\n"); );
    // Body
    Vtop___024root____Vdpiimwrap_top__DOT__u_data_mem__DOT__cpu_pmem_read_TOP(vlSelf->top__DOT__pc, vlSelf->__Vfunc_top__DOT__u_data_mem__DOT__cpu_pmem_read__3__Vfuncout);
    vlSelf->top__DOT__instr = vlSelf->__Vfunc_top__DOT__u_data_mem__DOT__cpu_pmem_read__3__Vfuncout;
    if ((0x100073U == vlSelf->top__DOT__instr)) {
        Vtop___024root____Vdpiimwrap_top__DOT__ebreak_TOP();
    }
    vlSelf->top__DOT__RD2 = ((0U == (0x1fU & (vlSelf->top__DOT__instr 
                                              >> 0x14U)))
                              ? 0U : vlSelf->top__DOT__u_register_file__DOT__reg_file
                             [(0x1fU & (vlSelf->top__DOT__instr 
                                        >> 0x14U))]);
    vlSelf->__Vtableidx1 = ((0x380U & (vlSelf->top__DOT__instr 
                                       >> 5U)) | (0x7fU 
                                                  & vlSelf->top__DOT__instr));
    vlSelf->top__DOT__reg_write = Vtop__ConstPool__TABLE_hd2f4e6a9_0
        [vlSelf->__Vtableidx1];
    vlSelf->top__DOT__imm_src = Vtop__ConstPool__TABLE_h2a6e909c_0
        [vlSelf->__Vtableidx1];
    vlSelf->top__DOT__alu_srcA = Vtop__ConstPool__TABLE_h35963e2c_0
        [vlSelf->__Vtableidx1];
    vlSelf->top__DOT__alu_srcB = Vtop__ConstPool__TABLE_h6a562c3a_0
        [vlSelf->__Vtableidx1];
    vlSelf->top__DOT__mem_write = Vtop__ConstPool__TABLE_h22430f06_0
        [vlSelf->__Vtableidx1];
    vlSelf->top__DOT__mem_en = Vtop__ConstPool__TABLE_hd9fef700_0
        [vlSelf->__Vtableidx1];
    vlSelf->top__DOT__mem_write_mask = Vtop__ConstPool__TABLE_h3b383ffb_0
        [vlSelf->__Vtableidx1];
    vlSelf->top__DOT__result_src = Vtop__ConstPool__TABLE_h36305c5d_0
        [vlSelf->__Vtableidx1];
    vlSelf->top__DOT__u_control_unit__DOT__branch = 
        Vtop__ConstPool__TABLE_h1e65f990_0[vlSelf->__Vtableidx1];
    vlSelf->top__DOT__u_control_unit__DOT__alu_op = 
        Vtop__ConstPool__TABLE_hd3c38cd5_0[vlSelf->__Vtableidx1];
    vlSelf->top__DOT__u_control_unit__DOT__jump = Vtop__ConstPool__TABLE_hca46ea29_0
        [vlSelf->__Vtableidx1];
    vlSelf->top__DOT__srcA = ((0U == (IData)(vlSelf->top__DOT__alu_srcA))
                               ? vlSelf->top__DOT__pc
                               : ((2U == (IData)(vlSelf->top__DOT__alu_srcA))
                                   ? ((0U == (0x1fU 
                                              & (vlSelf->top__DOT__instr 
                                                 >> 0xfU)))
                                       ? 0U : vlSelf->top__DOT__u_register_file__DOT__reg_file
                                      [(0x1fU & (vlSelf->top__DOT__instr 
                                                 >> 0xfU))])
                                   : 0U));
    vlSelf->__Vtableidx2 = ((0x40U & (vlSelf->top__DOT__instr 
                                      >> 0x18U)) | 
                            ((0x20U & vlSelf->top__DOT__instr) 
                             | ((0x1cU & (vlSelf->top__DOT__instr 
                                          >> 0xaU)) 
                                | (IData)(vlSelf->top__DOT__u_control_unit__DOT__alu_op))));
    vlSelf->top__DOT__alu_control = Vtop__ConstPool__TABLE_hdfd0dbe7_0
        [vlSelf->__Vtableidx2];
    vlSelf->top__DOT__imm_ext = ((4U & (IData)(vlSelf->top__DOT__imm_src))
                                  ? ((2U & (IData)(vlSelf->top__DOT__imm_src))
                                      ? 0U : ((1U & (IData)(vlSelf->top__DOT__imm_src))
                                               ? 0U
                                               : (0xfffff000U 
                                                  & vlSelf->top__DOT__instr)))
                                  : ((2U & (IData)(vlSelf->top__DOT__imm_src))
                                      ? ((1U & (IData)(vlSelf->top__DOT__imm_src))
                                          ? (((- (IData)(
                                                         (vlSelf->top__DOT__instr 
                                                          >> 0x1fU))) 
                                              << 0x14U) 
                                             | ((0xff000U 
                                                 & vlSelf->top__DOT__instr) 
                                                | ((0x800U 
                                                    & (vlSelf->top__DOT__instr 
                                                       >> 9U)) 
                                                   | (0x7feU 
                                                      & (vlSelf->top__DOT__instr 
                                                         >> 0x14U)))))
                                          : (((- (IData)(
                                                         (vlSelf->top__DOT__instr 
                                                          >> 0x1fU))) 
                                              << 0xcU) 
                                             | ((0x800U 
                                                 & (vlSelf->top__DOT__instr 
                                                    << 4U)) 
                                                | ((0x7e0U 
                                                    & (vlSelf->top__DOT__instr 
                                                       >> 0x14U)) 
                                                   | (0x1eU 
                                                      & (vlSelf->top__DOT__instr 
                                                         >> 7U))))))
                                      : ((1U & (IData)(vlSelf->top__DOT__imm_src))
                                          ? (((- (IData)(
                                                         (vlSelf->top__DOT__instr 
                                                          >> 0x1fU))) 
                                              << 0xcU) 
                                             | ((0xfe0U 
                                                 & (vlSelf->top__DOT__instr 
                                                    >> 0x14U)) 
                                                | (0x1fU 
                                                   & (vlSelf->top__DOT__instr 
                                                      >> 7U))))
                                          : (((- (IData)(
                                                         (vlSelf->top__DOT__instr 
                                                          >> 0x1fU))) 
                                              << 0xcU) 
                                             | (vlSelf->top__DOT__instr 
                                                >> 0x14U)))));
    vlSelf->top__DOT__srcB = ((0U == (IData)(vlSelf->top__DOT__alu_srcB))
                               ? vlSelf->top__DOT__RD2
                               : ((1U == (IData)(vlSelf->top__DOT__alu_srcB))
                                   ? vlSelf->top__DOT__imm_ext
                                   : 0U));
    vlSelf->top__DOT__u_alu__DOT__sum = (((1U & (IData)(vlSelf->top__DOT__alu_control))
                                           ? (~ vlSelf->top__DOT__srcB)
                                           : vlSelf->top__DOT__srcB) 
                                         + (vlSelf->top__DOT__srcA 
                                            + (1U & (IData)(vlSelf->top__DOT__alu_control))));
    vlSelf->top__DOT__alu_result = ((4U & (IData)(vlSelf->top__DOT__alu_control))
                                     ? ((2U & (IData)(vlSelf->top__DOT__alu_control))
                                         ? 0U : ((1U 
                                                  & (IData)(vlSelf->top__DOT__alu_control))
                                                  ? 
                                                 (1U 
                                                  & (((~ 
                                                       ((IData)(vlSelf->top__DOT__alu_control) 
                                                        >> 1U)) 
                                                      & ((~ 
                                                          ((IData)(vlSelf->top__DOT__alu_control) 
                                                           ^ 
                                                           ((vlSelf->top__DOT__srcA 
                                                             ^ vlSelf->top__DOT__srcB) 
                                                            >> 0x1fU))) 
                                                         & ((vlSelf->top__DOT__u_alu__DOT__sum 
                                                             ^ vlSelf->top__DOT__srcA) 
                                                            >> 0x1fU))) 
                                                     ^ 
                                                     (vlSelf->top__DOT__u_alu__DOT__sum 
                                                      >> 0x1fU)))
                                                  : 
                                                 (vlSelf->top__DOT__srcA 
                                                  ^ vlSelf->top__DOT__srcB)))
                                     : ((2U & (IData)(vlSelf->top__DOT__alu_control))
                                         ? ((1U & (IData)(vlSelf->top__DOT__alu_control))
                                             ? (vlSelf->top__DOT__srcA 
                                                | vlSelf->top__DOT__srcB)
                                             : (vlSelf->top__DOT__srcA 
                                                & vlSelf->top__DOT__srcB))
                                         : vlSelf->top__DOT__u_alu__DOT__sum));
    vlSelf->top__DOT__pc_next = ((((IData)(vlSelf->top__DOT__u_control_unit__DOT__branch) 
                                   & (0U == vlSelf->top__DOT__alu_result)) 
                                  | (IData)(vlSelf->top__DOT__u_control_unit__DOT__jump))
                                  ? vlSelf->top__DOT__alu_result
                                  : ((IData)(4U) + vlSelf->top__DOT__pc));
    if (vlSelf->top__DOT__mem_en) {
        Vtop___024root____Vdpiimwrap_top__DOT__u_data_mem__DOT__cpu_pmem_read_TOP(vlSelf->top__DOT__alu_result, vlSelf->__Vfunc_top__DOT__u_data_mem__DOT__cpu_pmem_read__1__Vfuncout);
        vlSelf->top__DOT__read_data = vlSelf->__Vfunc_top__DOT__u_data_mem__DOT__cpu_pmem_read__1__Vfuncout;
        if (vlSelf->top__DOT__mem_write) {
            Vtop___024root____Vdpiimwrap_top__DOT__u_data_mem__DOT__cpu_pmem_write_TOP(vlSelf->top__DOT__alu_result, vlSelf->top__DOT__RD2, 4U);
        }
    } else {
        vlSelf->top__DOT__read_data = 0U;
    }
}

VL_ATTR_COLD void Vtop___024root___eval_stl(Vtop___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    Vtop__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    Vtop___024root___eval_stl\n"); );
    // Body
    if (vlSelf->__VstlTriggered.at(0U)) {
        Vtop___024root___stl_sequent__TOP__0(vlSelf);
        vlSelf->__Vm_traceActivity[3U] = 1U;
        vlSelf->__Vm_traceActivity[2U] = 1U;
        vlSelf->__Vm_traceActivity[1U] = 1U;
        vlSelf->__Vm_traceActivity[0U] = 1U;
    }
}

#ifdef VL_DEBUG
VL_ATTR_COLD void Vtop___024root___dump_triggers__act(Vtop___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    Vtop__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    Vtop___024root___dump_triggers__act\n"); );
    // Body
    if ((1U & (~ (IData)(vlSelf->__VactTriggered.any())))) {
        VL_DBG_MSGF("         No triggers active\n");
    }
    if (vlSelf->__VactTriggered.at(0U)) {
        VL_DBG_MSGF("         'act' region trigger index 0 is active: @(posedge clk or negedge rst_n)\n");
    }
    if (vlSelf->__VactTriggered.at(1U)) {
        VL_DBG_MSGF("         'act' region trigger index 1 is active: @(posedge clk)\n");
    }
}
#endif  // VL_DEBUG

#ifdef VL_DEBUG
VL_ATTR_COLD void Vtop___024root___dump_triggers__nba(Vtop___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    Vtop__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    Vtop___024root___dump_triggers__nba\n"); );
    // Body
    if ((1U & (~ (IData)(vlSelf->__VnbaTriggered.any())))) {
        VL_DBG_MSGF("         No triggers active\n");
    }
    if (vlSelf->__VnbaTriggered.at(0U)) {
        VL_DBG_MSGF("         'nba' region trigger index 0 is active: @(posedge clk or negedge rst_n)\n");
    }
    if (vlSelf->__VnbaTriggered.at(1U)) {
        VL_DBG_MSGF("         'nba' region trigger index 1 is active: @(posedge clk)\n");
    }
}
#endif  // VL_DEBUG

VL_ATTR_COLD void Vtop___024root___ctor_var_reset(Vtop___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    Vtop__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    Vtop___024root___ctor_var_reset\n"); );
    // Body
    vlSelf->clk = VL_RAND_RESET_I(1);
    vlSelf->rst_n = VL_RAND_RESET_I(1);
    vlSelf->top__DOT__pc_next = VL_RAND_RESET_I(32);
    vlSelf->top__DOT__instr = VL_RAND_RESET_I(32);
    vlSelf->top__DOT__reg_write = VL_RAND_RESET_I(1);
    vlSelf->top__DOT__imm_src = VL_RAND_RESET_I(3);
    vlSelf->top__DOT__alu_srcA = VL_RAND_RESET_I(2);
    vlSelf->top__DOT__alu_srcB = VL_RAND_RESET_I(2);
    vlSelf->top__DOT__mem_write = VL_RAND_RESET_I(1);
    vlSelf->top__DOT__mem_write_mask = VL_RAND_RESET_I(4);
    vlSelf->top__DOT__mem_en = VL_RAND_RESET_I(1);
    vlSelf->top__DOT__result_src = VL_RAND_RESET_I(2);
    vlSelf->top__DOT__alu_control = VL_RAND_RESET_I(3);
    vlSelf->top__DOT__RD2 = VL_RAND_RESET_I(32);
    vlSelf->top__DOT__imm_ext = VL_RAND_RESET_I(32);
    vlSelf->top__DOT__srcA = VL_RAND_RESET_I(32);
    vlSelf->top__DOT__srcB = VL_RAND_RESET_I(32);
    vlSelf->top__DOT__alu_result = VL_RAND_RESET_I(32);
    vlSelf->top__DOT__read_data = VL_RAND_RESET_I(32);
    vlSelf->top__DOT__pc = VL_RAND_RESET_I(32);
    vlSelf->top__DOT__u_control_unit__DOT__branch = VL_RAND_RESET_I(1);
    vlSelf->top__DOT__u_control_unit__DOT__jump = VL_RAND_RESET_I(1);
    vlSelf->top__DOT__u_control_unit__DOT__alu_op = VL_RAND_RESET_I(2);
    for (int __Vi0 = 0; __Vi0 < 32; ++__Vi0) {
        vlSelf->top__DOT__u_register_file__DOT__reg_file[__Vi0] = VL_RAND_RESET_I(32);
    }
    vlSelf->top__DOT__u_alu__DOT__sum = VL_RAND_RESET_I(32);
    vlSelf->__Vfunc_top__DOT__u_data_mem__DOT__cpu_pmem_read__1__Vfuncout = 0;
    vlSelf->__Vfunc_top__DOT__u_data_mem__DOT__cpu_pmem_read__3__Vfuncout = 0;
    vlSelf->__Vtableidx1 = 0;
    vlSelf->__Vtableidx2 = 0;
    vlSelf->__Vtrigrprev__TOP__clk = VL_RAND_RESET_I(1);
    vlSelf->__Vtrigrprev__TOP__rst_n = VL_RAND_RESET_I(1);
    for (int __Vi0 = 0; __Vi0 < 4; ++__Vi0) {
        vlSelf->__Vm_traceActivity[__Vi0] = 0;
    }
}
